// XTPPropertyGridItemNumber.cpp : implementation of the CXTPPropertyGridItemNumber class.
//
// This file is a part of the XTREME PROPERTYGRID MFC class library.
// (c)1998-2012 Codejock Software, All Rights Reserved.
//
// THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
// RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
// CONSENT OF CODEJOCK SOFTWARE.
//
// THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
// IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
// YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
// SINGLE COMPUTER.
//
// CONTACT INFORMATION:
// support@codejock.com
// http://www.codejock.com
//
/////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "XTPPropertyGridItemShort.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CXTPPropertyGridItemShort
IMPLEMENT_DYNAMIC(CXTPPropertyGridItemShort, CXTPPropertyGridItem)


CXTPPropertyGridItemShort::CXTPPropertyGridItemShort(LPCTSTR strCaption, short nValue, short* pBindNumber)
	: CXTPPropertyGridItem(strCaption)
{
	m_pBindNumber = pBindNumber;
	SetNumber(nValue);
	m_strDefaultValue = m_strValue;
}
CXTPPropertyGridItemShort::CXTPPropertyGridItemShort(UINT nID, short nValue, short* pBindNumber)
	: CXTPPropertyGridItem(nID)
{
	m_pBindNumber = pBindNumber;
	SetNumber(nValue);
	m_strDefaultValue = m_strValue;
}

CXTPPropertyGridItemShort::~CXTPPropertyGridItemShort()
{
}

/////////////////////////////////////////////////////////////////////////////
//

void CXTPPropertyGridItemShort::SetValue(CString strValue)
{
	SetNumber(_ttoi(strValue));
}

void CXTPPropertyGridItemShort::SetNumber(short nValue)
{
	m_nValue = nValue;

	if (m_pBindNumber)
	{
		*m_pBindNumber = m_nValue;
	}

	CString strValue;
	strValue.Format(_T("%i"), nValue);
	CXTPPropertyGridItem::SetValue(strValue);
}

void CXTPPropertyGridItemShort::BindToNumber(short* pBindNumber)
{
	m_pBindNumber = pBindNumber;
	if (m_pBindNumber)
	{
		*m_pBindNumber = m_nValue;
	}
}

void CXTPPropertyGridItemShort::OnBeforeInsert()
{
	if (m_pBindNumber && *m_pBindNumber != m_nValue)
	{
		SetNumber(*m_pBindNumber);
	}
}
AFX_INLINE short CXTPPropertyGridItemShort::GetNumber() const {
	return m_nValue;
}
